//
//  CMyPlane.cpp
//  MyPlaneGame
//
//  Created by yeates on 16/6/9.
//  Copyright (c) 2016年 yeates. All rights reserved.
//

#include "CMyPlane.h"

CMyPlane::CMyPlane(){
    posx = 275, posy = 450;
    speed = 10;
    MyPlaneImg = cvLoadImage("./resource/_airport_1.png");
}

CMyPlane::~CMyPlane(){

}

//void CMyPlane::Move(int MHeight, int MWidth){
//    if(GetAsyncKeyState('W') & 0x8000)  posy -= speed;
//    if(GetAsyncKeyState('S') & 0x8000)  posy += speed;
//    if(GetAsyncKeyState('A') & 0x8000)  posx -= speed;
//    if(GetAsyncKeyState('D') & 0x8000)  posx += speed;
//    if(posx < 0)
//}
void CMyPlane::Draw(IplImage *Bg){
    int cr, cg, cb;         //表示背景色的rgb值
    cr = CV_IMAGE_ELEM(MyPlaneImg, uchar, 0, 0);
    cg = CV_IMAGE_ELEM(MyPlaneImg, uchar, 0, 1);
    cb = CV_IMAGE_ELEM(MyPlaneImg, uchar, 0, 2);
    for(int i = 0; i < MyPlaneImg->height; i++){
        for(int j = 0; j < MyPlaneImg->width; j++){
            int r, g, b;
            r = CV_IMAGE_ELEM(MyPlaneImg, uchar, i, j*3+0);
            g = CV_IMAGE_ELEM(MyPlaneImg, uchar, i, j*3+1);
            b = CV_IMAGE_ELEM(MyPlaneImg, uchar, i, j*3+2);
            
            int absr, absg, absb;       //rgb差值
            absr = abs(cr - r);
            absg = abs(cg - g);
            absb = abs(cb - b);
            if(absr < 5 && absg < 5 && absb < 5)    continue;           //消去背景色
            CV_IMAGE_ELEM(Bg, uchar, i + posy, (j + posx)*3+0) = r;
            CV_IMAGE_ELEM(Bg, uchar, i + posy, (j + posx)*3+1) = g;
            CV_IMAGE_ELEM(Bg, uchar, i + posy, (j + posx)*3+2) = b;
        }
    }
    
}
